package com.kaidongyuan.app.kdydriverr.ui.base;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.hardware.Camera;

import com.kaidongyuan.app.kdydriverr.serviceAndReceiver.CameraManager;
import com.kaidongyuan.app.kdydriverr.ui.activity.hbx;

public class ScanCodeBroadcastReceiver extends BroadcastReceiver {
    com.kaidongyuan.app.kdydriverr.ui.activity.hbx hbx;
    CameraManager cameraManager;

    public ScanCodeBroadcastReceiver(hbx hbx, CameraManager cameraManager){
        this.hbx = hbx;
        this.cameraManager = cameraManager;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        String barCode = intent.getStringExtra("scannerdata");
        if(barCode == null || barCode == "") {
            barCode = intent.getStringExtra("Scan_context");
        }
        if(barCode == null || barCode == "") {
            barCode = intent.getStringExtra("barcode_string");
        }
        if(barCode == null || barCode == "") {
            barCode = intent.getStringExtra("value");
        }

        if(barCode != null && barCode != ""){
            this.cameraManager.takePicture(new Camera.PictureCallback() {
                @Override
                public void onPictureTaken(byte[] data, Camera camera) {
                    // 处理拍摄的照片数据，可以保存或者进一步处理
//                    hbx.showDialog(data);
                }
            });

        }
        this.hbx.showDialog(barCode);
    }
}
